/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.collection.CollUtil
 *  cn.hutool.core.util.ObjectUtil
 *  com.alibaba.fastjson.JSON
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.collections.FXCollections
 *  javafx.collections.ObservableList
 *  javafx.event.EventHandler
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.Node
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.Button
 *  javafx.scene.control.CheckBox
 *  javafx.scene.control.ScrollPane
 *  javafx.scene.control.TableCell
 *  javafx.scene.control.TableColumn
 *  javafx.scene.control.TableView
 *  javafx.scene.control.cell.PropertyValueFactory
 *  javafx.scene.input.KeyCode
 *  javafx.scene.input.KeyEvent
 *  javafx.scene.layout.AnchorPane
 *  javafx.scene.layout.VBox
 *  javafx.stage.Stage
 *  javafx.util.Callback
 *  org.springframework.beans.factory.annotation.Autowired
 *  org.springframework.util.CollectionUtils
 */
package com.gys.controller.examine;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.gys.common.business.ExamineUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.util.ConstUtil;
import com.gys.common.util.SpringUtil;
import com.gys.controller.BaseController;
import com.gys.controller.examine.ExamineController;
import com.gys.controller.index.IndexController;
import com.gys.controller.salesReceipts.TipTopController;
import com.gys.data.accept.AcceptOutData;
import com.gys.data.examine.GetExamineInData;
import com.gys.view.examine.AddView;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Callback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;

@FXMLController
public class AddExamineController
extends BaseController
implements Initializable {
    private final int pageSize = ConstUtil.DEFAULT_PAGESIZE;
    private final int defaultPageCount = ConstUtil.DEFAULT_PAGECOUNT;
    private ObservableList<AcceptOutData> observableTableList = FXCollections.observableArrayList(new ArrayList());
    @FXML
    private AnchorPane anchorPane;
    @FXML
    private ScrollPane scrollPane;
    @FXML
    private VBox vBox;
    @FXML
    private Button enterBtn;
    @FXML
    private TableView<AcceptOutData> tableView;
    @FXML
    private TableColumn<AcceptOutData, CheckBox> checkBox;
    @FXML
    private TableColumn<AcceptOutData, String> gsahVoucherId;
    @FXML
    private TableColumn<AcceptOutData, String> gsahDate;
    @FXML
    private TableColumn<AcceptOutData, String> gsahType;
    @FXML
    private TableColumn<AcceptOutData, String> gsahTotalAmt;
    @FXML
    private TableColumn<AcceptOutData, String> gsahTotalQty;
    @Autowired
    private ExamineController examineController;
    @Autowired
    private TipTopController tipTopController;
    @Autowired
    private IndexController indexController;
    private Timer timer = new Timer();

    public void initialize(URL location, ResourceBundle resources) {
        this.anchorPane.setPrefWidth(this.getContentWidth() - 400.0);
        this.anchorPane.setPrefHeight(this.getContentHeight() - 200.0);
        this.scrollPane.setPrefWidth(this.getContentWidth() - 400.0);
        this.scrollPane.setPrefHeight(this.getContentHeight() - 200.0);
        this.vBox.setPrefWidth(this.getContentWidth() - 400.0);
        this.vBox.setPrefHeight(this.getContentHeight() - 200.0);
        this.tableView.setPrefWidth(this.getContentWidth() - 400.0);
        this.initTable();
    }

    @Override
    public void init() {
        this.timer.schedule(new TimerTask(){

            @Override
            public void run() {
                AddView view = SpringUtil.getBean(AddView.class);
                Stage stage = (Stage)view.getView().getScene().getWindow();
                stage.getScene().setOnKeyReleased((EventHandler)new EventHandler<KeyEvent>(){

                    public void handle(KeyEvent event) {
                        if (event.getCode() == KeyCode.ENTER) {
                            AddExamineController.this.saveAdd();
                            return;
                        }
                        if (event.getCode() == KeyCode.ESCAPE) {
                            AddExamineController.this.closeWindows();
                            return;
                        }
                    }
                });
            }
        }, 1000L);
        this.initTable();
    }

    @FXML
    private void saveAdd() {
        Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", null);
        List<Integer> indexList = this.getSelectIndex();
        if (ObjectUtil.isEmpty(indexList)) {
            alert.setContentText("\u8bf7\u9009\u62e9\u8bb0\u5f55");
            alert.showAndWait();
            return;
        }
        String voucherId = "";
        for (Integer index : indexList) {
            voucherId = ((AcceptOutData)this.observableTableList.get(index - 1)).getGsahVoucherId();
        }
        GetExamineInData inData = new GetExamineInData();
        inData.setGsehVoucherAcceptId(voucherId);
        HttpJson rsp = ExamineUtil.save(inData);
        if (rsp.isSuccess()) {
            this.examineController.initTable(0, voucherId);
            this.init();
            this.anchorPane.getScene().getWindow().hide();
        } else {
            alert.showAndWait();
        }
    }

    @FXML
    private void closeWindows() {
        this.init();
        this.anchorPane.getScene().getWindow().hide();
    }

    public TableView<AcceptOutData> initTable() {
        this.tipTopController.initTitle("\u8c03\u53d6\u6536\u8d27\u5355");
        GetExamineInData inData = new GetExamineInData();
        HttpJson rsp = ExamineUtil.acceptList(inData);
        if (!rsp.isSuccess()) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", rsp.getMsg());
            alert.showAndWait();
            return new TableView();
        }
        List<AcceptOutData> list = JSON.parseArray((String)rsp.getMsg(), AcceptOutData.class);
        int i = 0;
        for (AcceptOutData outData : list) {
            if ("1".equals(outData.getGsahType())) {
                outData.setGsahType("\u914d\u9001\u5355");
            } else {
                outData.setGsahType("\u91c7\u8d2d\u5355");
            }
            outData.setIndex(i + 1);
            ++i;
        }
        this.observableTableList.clear();
        this.observableTableList = FXCollections.observableArrayList((Collection)list);
        this.bingTableCell();
        this.tableView.setItems(this.observableTableList);
        return this.tableView;
    }

    private void bingTableCell() {
        this.checkBox.setCellValueFactory(cellData -> ((AcceptOutData)cellData.getValue()).getCheckBox().getCustomCheckBox());
        this.checkBox.setCellFactory(col -> {
            TableCell<AcceptOutData, CheckBox> cell = new TableCell<AcceptOutData, CheckBox>(){

                protected void updateItem(CheckBox item, boolean empty) {
                    super.updateItem(item, empty);
                    this.setGraphic((Node)item);
                    if (item != null) {
                        item.setOnMouseClicked(col -> {
                            if (CollUtil.isEmpty((Collection)AddExamineController.this.observableTableList)) {
                                return;
                            }
                            int index = this.getIndex();
                            for (int i = 0; i < AddExamineController.this.observableTableList.size(); ++i) {
                                if (i == index) continue;
                                ((AcceptOutData)AddExamineController.this.observableTableList.get(i)).getCheckBox().setSelectStatus(false);
                            }
                        });
                    }
                }
            };
            return cell;
        });
        this.gsahVoucherId.setCellValueFactory((Callback)new PropertyValueFactory(this.gsahVoucherId.getId()));
        this.gsahDate.setCellValueFactory((Callback)new PropertyValueFactory(this.gsahDate.getId()));
        this.gsahType.setCellValueFactory((Callback)new PropertyValueFactory(this.gsahType.getId()));
        this.gsahTotalAmt.setCellValueFactory((Callback)new PropertyValueFactory(this.gsahTotalAmt.getId()));
        this.gsahTotalQty.setCellValueFactory((Callback)new PropertyValueFactory(this.gsahTotalQty.getId()));
    }

    private List<Integer> getSelectIndex() {
        ArrayList<Integer> ids = new ArrayList<Integer>();
        if (!CollectionUtils.isEmpty(this.observableTableList)) {
            for (AcceptOutData i : this.observableTableList) {
                if (!i.getCheckBox().isSelected().booleanValue()) continue;
                ids.add(i.getIndex());
            }
        }
        return ids;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public int getDefaultPageCount() {
        return this.defaultPageCount;
    }

    public ObservableList<AcceptOutData> getObservableTableList() {
        return this.observableTableList;
    }

    public AnchorPane getAnchorPane() {
        return this.anchorPane;
    }

    public ScrollPane getScrollPane() {
        return this.scrollPane;
    }

    public VBox getVBox() {
        return this.vBox;
    }

    public Button getEnterBtn() {
        return this.enterBtn;
    }

    public TableView<AcceptOutData> getTableView() {
        return this.tableView;
    }

    public TableColumn<AcceptOutData, CheckBox> getCheckBox() {
        return this.checkBox;
    }

    public TableColumn<AcceptOutData, String> getGsahVoucherId() {
        return this.gsahVoucherId;
    }

    public TableColumn<AcceptOutData, String> getGsahDate() {
        return this.gsahDate;
    }

    public TableColumn<AcceptOutData, String> getGsahType() {
        return this.gsahType;
    }

    public TableColumn<AcceptOutData, String> getGsahTotalAmt() {
        return this.gsahTotalAmt;
    }

    public TableColumn<AcceptOutData, String> getGsahTotalQty() {
        return this.gsahTotalQty;
    }

    public ExamineController getExamineController() {
        return this.examineController;
    }

    public TipTopController getTipTopController() {
        return this.tipTopController;
    }

    public IndexController getIndexController() {
        return this.indexController;
    }

    public Timer getTimer() {
        return this.timer;
    }

    public void setObservableTableList(ObservableList<AcceptOutData> observableTableList) {
        this.observableTableList = observableTableList;
    }

    public void setAnchorPane(AnchorPane anchorPane) {
        this.anchorPane = anchorPane;
    }

    public void setScrollPane(ScrollPane scrollPane) {
        this.scrollPane = scrollPane;
    }

    public void setVBox(VBox vBox) {
        this.vBox = vBox;
    }

    public void setEnterBtn(Button enterBtn) {
        this.enterBtn = enterBtn;
    }

    public void setTableView(TableView<AcceptOutData> tableView) {
        this.tableView = tableView;
    }

    public void setCheckBox(TableColumn<AcceptOutData, CheckBox> checkBox) {
        this.checkBox = checkBox;
    }

    public void setGsahVoucherId(TableColumn<AcceptOutData, String> gsahVoucherId) {
        this.gsahVoucherId = gsahVoucherId;
    }

    public void setGsahDate(TableColumn<AcceptOutData, String> gsahDate) {
        this.gsahDate = gsahDate;
    }

    public void setGsahType(TableColumn<AcceptOutData, String> gsahType) {
        this.gsahType = gsahType;
    }

    public void setGsahTotalAmt(TableColumn<AcceptOutData, String> gsahTotalAmt) {
        this.gsahTotalAmt = gsahTotalAmt;
    }

    public void setGsahTotalQty(TableColumn<AcceptOutData, String> gsahTotalQty) {
        this.gsahTotalQty = gsahTotalQty;
    }

    public void setExamineController(ExamineController examineController) {
        this.examineController = examineController;
    }

    public void setTipTopController(TipTopController tipTopController) {
        this.tipTopController = tipTopController;
    }

    public void setIndexController(IndexController indexController) {
        this.indexController = indexController;
    }

    public void setTimer(Timer timer) {
        this.timer = timer;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof AddExamineController)) {
            return false;
        }
        AddExamineController other = (AddExamineController)o;
        if (!other.canEqual(this)) {
            return false;
        }
        if (this.getPageSize() != other.getPageSize()) {
            return false;
        }
        if (this.getDefaultPageCount() != other.getDefaultPageCount()) {
            return false;
        }
        ObservableList<AcceptOutData> this$observableTableList = this.getObservableTableList();
        ObservableList<AcceptOutData> other$observableTableList = other.getObservableTableList();
        if (this$observableTableList == null ? other$observableTableList != null : !this$observableTableList.equals(other$observableTableList)) {
            return false;
        }
        AnchorPane this$anchorPane = this.getAnchorPane();
        AnchorPane other$anchorPane = other.getAnchorPane();
        if (this$anchorPane == null ? other$anchorPane != null : !this$anchorPane.equals(other$anchorPane)) {
            return false;
        }
        ScrollPane this$scrollPane = this.getScrollPane();
        ScrollPane other$scrollPane = other.getScrollPane();
        if (this$scrollPane == null ? other$scrollPane != null : !this$scrollPane.equals(other$scrollPane)) {
            return false;
        }
        VBox this$vBox = this.getVBox();
        VBox other$vBox = other.getVBox();
        if (this$vBox == null ? other$vBox != null : !this$vBox.equals(other$vBox)) {
            return false;
        }
        Button this$enterBtn = this.getEnterBtn();
        Button other$enterBtn = other.getEnterBtn();
        if (this$enterBtn == null ? other$enterBtn != null : !this$enterBtn.equals(other$enterBtn)) {
            return false;
        }
        TableView<AcceptOutData> this$tableView = this.getTableView();
        TableView<AcceptOutData> other$tableView = other.getTableView();
        if (this$tableView == null ? other$tableView != null : !this$tableView.equals(other$tableView)) {
            return false;
        }
        TableColumn<AcceptOutData, CheckBox> this$checkBox = this.getCheckBox();
        TableColumn<AcceptOutData, CheckBox> other$checkBox = other.getCheckBox();
        if (this$checkBox == null ? other$checkBox != null : !this$checkBox.equals(other$checkBox)) {
            return false;
        }
        TableColumn<AcceptOutData, String> this$gsahVoucherId = this.getGsahVoucherId();
        TableColumn<AcceptOutData, String> other$gsahVoucherId = other.getGsahVoucherId();
        if (this$gsahVoucherId == null ? other$gsahVoucherId != null : !this$gsahVoucherId.equals(other$gsahVoucherId)) {
            return false;
        }
        TableColumn<AcceptOutData, String> this$gsahDate = this.getGsahDate();
        TableColumn<AcceptOutData, String> other$gsahDate = other.getGsahDate();
        if (this$gsahDate == null ? other$gsahDate != null : !this$gsahDate.equals(other$gsahDate)) {
            return false;
        }
        TableColumn<AcceptOutData, String> this$gsahType = this.getGsahType();
        TableColumn<AcceptOutData, String> other$gsahType = other.getGsahType();
        if (this$gsahType == null ? other$gsahType != null : !this$gsahType.equals(other$gsahType)) {
            return false;
        }
        TableColumn<AcceptOutData, String> this$gsahTotalAmt = this.getGsahTotalAmt();
        TableColumn<AcceptOutData, String> other$gsahTotalAmt = other.getGsahTotalAmt();
        if (this$gsahTotalAmt == null ? other$gsahTotalAmt != null : !this$gsahTotalAmt.equals(other$gsahTotalAmt)) {
            return false;
        }
        TableColumn<AcceptOutData, String> this$gsahTotalQty = this.getGsahTotalQty();
        TableColumn<AcceptOutData, String> other$gsahTotalQty = other.getGsahTotalQty();
        if (this$gsahTotalQty == null ? other$gsahTotalQty != null : !this$gsahTotalQty.equals(other$gsahTotalQty)) {
            return false;
        }
        ExamineController this$examineController = this.getExamineController();
        ExamineController other$examineController = other.getExamineController();
        if (this$examineController == null ? other$examineController != null : !(this$examineController).equals(other$examineController)) {
            return false;
        }
        TipTopController this$tipTopController = this.getTipTopController();
        TipTopController other$tipTopController = other.getTipTopController();
        if (this$tipTopController == null ? other$tipTopController != null : !(this$tipTopController).equals(other$tipTopController)) {
            return false;
        }
        IndexController this$indexController = this.getIndexController();
        IndexController other$indexController = other.getIndexController();
        if (this$indexController == null ? other$indexController != null : !(this$indexController).equals(other$indexController)) {
            return false;
        }
        Timer this$timer = this.getTimer();
        Timer other$timer = other.getTimer();
        return !(this$timer == null ? other$timer != null : !this$timer.equals(other$timer));
    }

    protected boolean canEqual(Object other) {
        return other instanceof AddExamineController;
    }

    public int hashCode() {
        int PRIME = 59;
        int result = 1;
        result = result * 59 + this.getPageSize();
        result = result * 59 + this.getDefaultPageCount();
        ObservableList<AcceptOutData> $observableTableList = this.getObservableTableList();
        result = result * 59 + ($observableTableList == null ? 43 : $observableTableList.hashCode());
        AnchorPane $anchorPane = this.getAnchorPane();
        result = result * 59 + ($anchorPane == null ? 43 : $anchorPane.hashCode());
        ScrollPane $scrollPane = this.getScrollPane();
        result = result * 59 + ($scrollPane == null ? 43 : $scrollPane.hashCode());
        VBox $vBox = this.getVBox();
        result = result * 59 + ($vBox == null ? 43 : $vBox.hashCode());
        Button $enterBtn = this.getEnterBtn();
        result = result * 59 + ($enterBtn == null ? 43 : $enterBtn.hashCode());
        TableView<AcceptOutData> $tableView = this.getTableView();
        result = result * 59 + ($tableView == null ? 43 : $tableView.hashCode());
        TableColumn<AcceptOutData, CheckBox> $checkBox = this.getCheckBox();
        result = result * 59 + ($checkBox == null ? 43 : $checkBox.hashCode());
        TableColumn<AcceptOutData, String> $gsahVoucherId = this.getGsahVoucherId();
        result = result * 59 + ($gsahVoucherId == null ? 43 : $gsahVoucherId.hashCode());
        TableColumn<AcceptOutData, String> $gsahDate = this.getGsahDate();
        result = result * 59 + ($gsahDate == null ? 43 : $gsahDate.hashCode());
        TableColumn<AcceptOutData, String> $gsahType = this.getGsahType();
        result = result * 59 + ($gsahType == null ? 43 : $gsahType.hashCode());
        TableColumn<AcceptOutData, String> $gsahTotalAmt = this.getGsahTotalAmt();
        result = result * 59 + ($gsahTotalAmt == null ? 43 : $gsahTotalAmt.hashCode());
        TableColumn<AcceptOutData, String> $gsahTotalQty = this.getGsahTotalQty();
        result = result * 59 + ($gsahTotalQty == null ? 43 : $gsahTotalQty.hashCode());
        ExamineController $examineController = this.getExamineController();
        result = result * 59 + ($examineController == null ? 43 : ($examineController).hashCode());
        TipTopController $tipTopController = this.getTipTopController();
        result = result * 59 + ($tipTopController == null ? 43 : ($tipTopController).hashCode());
        IndexController $indexController = this.getIndexController();
        result = result * 59 + ($indexController == null ? 43 : ($indexController).hashCode());
        Timer $timer = this.getTimer();
        result = result * 59 + ($timer == null ? 43 : $timer.hashCode());
        return result;
    }

    public String toString() {
        return "AddExamineController(pageSize=" + this.getPageSize() + ", defaultPageCount=" + this.getDefaultPageCount() + ", observableTableList=" + this.getObservableTableList() + ", anchorPane=" + this.getAnchorPane() + ", scrollPane=" + this.getScrollPane() + ", vBox=" + this.getVBox() + ", enterBtn=" + this.getEnterBtn() + ", tableView=" + this.getTableView() + ", checkBox=" + this.getCheckBox() + ", gsahVoucherId=" + this.getGsahVoucherId() + ", gsahDate=" + this.getGsahDate() + ", gsahType=" + this.getGsahType() + ", gsahTotalAmt=" + this.getGsahTotalAmt() + ", gsahTotalQty=" + this.getGsahTotalQty() + ", examineController=" + this.getExamineController() + ", tipTopController=" + this.getTipTopController() + ", indexController=" + this.getIndexController() + ", timer=" + this.getTimer() + ")";
    }
}

